package net.huashitong.zhApp.controller;

import com.sirdc.modules.utils.ObjectUtils;
import net.huashitong.Project.entity.EarlyWarningNode;
import net.huashitong.Project.filter.EarlyWarningNodeFilter;
import net.huashitong.Project.service.EarlyWarningNodeService;
import net.huashitong.user.entity.BnpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/zhApp/earlyWarning")
public class AppEarlyWarningController extends BaseCtrl {

    @Autowired
    private EarlyWarningNodeService earlyWarningNodeService;

    @ResponseBody
    @RequestMapping(value = "/lists", method = RequestMethod.POST)
    public Map<String, Object> warningList(@RequestBody EarlyWarningNodeFilter filter) {


        BnpUser user = queryUserAuth(filter.getUserPhone());
        if(ObjectUtils.isBlank(user)){
            return coverMessage("202", "无用户权限");
        }
        if (!"2".equals(user.getBranchType())) {
            filter.setOperatorUser(user.getName());
        }
        List<EarlyWarningNode> list = earlyWarningNodeService.queryEarlyWarning(filter);
        Map<String, Object> result = new HashMap<>();
        result.put("code", "200");
        result.put("message", "成功获取数据");
        if (list.size() == 0) {
            result.put("model", new ArrayList<>());
            result.put("count", 0);
        } else {
//            filter.setState("0");
            result.put("model", list);
            result.put("count", filter.getPaging().getRecords());
        }
        return result;
    }
}
